using RuoVea.ExEnum;
using RuoVea.ExSugar.Attributes;
using RuoVea.ExSugar.Entity;
using SqlSugar;
using System.ComponentModel.DataAnnotations;

namespace RuoVea.OmiApi.Reports.Models;

/// <summary>
/// 报表查询SQL
/// </summary>
[SugarTable(nameof(RptSql),"报表SQL")]
[SugarIndex($"IX_{nameof(RptSql)}_{nameof(Code)}", nameof(Code), OrderByType.Asc)]
[SugarIndex($"IX_{nameof(RptSql)}_{nameof(SqlName)}", nameof(SqlName), OrderByType.Asc)]
[SugarIndex($"IX_{nameof(RptSql)}_{nameof(IsEnabled)}", nameof(IsEnabled), OrderByType.Asc)]
[SugarIndex($"IX_{nameof(RptSql)}_{nameof(CreateTime)}", nameof(CreateTime), OrderByType.Desc)]
public class RptSql : EntityBase
{
    /// <summary>
    /// 代码
    /// </summary>
    [Required, MaxLength(100)]
    [ConfigSugarColumn(nameof(Code), columnDescription : "代码", isNullable:true)]
    public string Code { get; set; }

    /// <summary>
    /// SQL名称
    /// </summary>
    [Required, MaxLength(100)]
    [ConfigSugarColumn(nameof(SqlName),columnDescription : "SQL名称")]
    public string SqlName { get; set; }

    /// <summary>
    /// 所属数据源ID
    /// </summary>
    [ConfigSugarColumn(nameof(DatabaseId),columnDescription : "数据源ID")]
    public long? DatabaseId { get; set; }

    /// <summary>
    /// 查询SQL语句
    /// </summary>
    [Required]
    [ConfigSugarColumn(nameof(QuerySql),columnDescription : "查询SQL", ColumnDataType = StaticConfig.CodeFirst_BigString)]
    public string QuerySql { get; set; }

    /// <summary>
    /// 是否启用
    /// </summary>
    [ConfigSugarColumn(nameof(IsEnabled),columnDescription : "是否启用", DefaultValue = "1")]
    public YesOrNot? IsEnabled { get; set; } = YesOrNot.Y;

    /// <summary>
    /// 排序号
    /// </summary>
    [ConfigSugarColumn(nameof(Sort),columnDescription : "排序号", IsNullable = true, DefaultValue = "10")]
    public int? Sort { get; set; }

    /// <summary>
    /// 备注说明
    /// </summary>
    [MaxLength(500)]
    [ConfigSugarColumn(nameof(Remark),columnDescription : "备注", IsNullable = true, ColumnDataType = StaticConfig.CodeFirst_BigString)]
    public string Remark { get; set; }
}